package com.mooc.swxy.task;

/**
 * @author Siaze
 * @date 2022/4/19
 */

import com.alibaba.fastjson.JSON;
import com.mooc.swxy.pojo.Chapter;
import com.mooc.swxy.system.ReqURL;
import com.mooc.swxy.system.ResponseMap;
import com.mooc.swxy.tool.RequestTool;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.MediaType;
import java.util.Map;


public class WkTask {

    /**
     * 日志
     */
    private static final Logger logger = LoggerFactory.getLogger(WkTask.class);

    /**
     * 请求工具
     */
    private RequestTool requestTool;

    public WkTask(RequestTool tools) {
        this.requestTool = tools;
    }

    /**
     * 获取章节信息， 并执行任务
     * @param params 请求的基本参数 token、version等
     * @return
     */
    public ResponseMap chapter(Map params) {
        String s = requestTool.postRequest(ReqURL.BASE_URL.concat(ReqURL.COURSE_CHAPTER_URL), MediaType.MULTIPART_FORM_DATA, params, String.class);
        Chapter chapter = JSON.parseObject(s, Chapter.class);
        new WkService(params.get("courseId").toString(), params.get("token").toString() ,chapter.getResult().getList(), params.get("courseId").toString()).start();
        return new ResponseMap(200,"操作成功").putData("chapter",chapter.getResult().getList());
    }

}